<?php
/**
 * The following code, none of which has BUG.
 *
 * @author: BD<657306123@qq.com>
 */
declare (strict_types = 1);

namespace app\common\service;

use think\facade\Event;
use think\facade\Log;

class SafeEventEmitter{

	/**
	 * 触发事件
	 *
	 * @access public
	 * @param string|object $event 事件名称
	 * @param mixed         $params 传入参数
	 * @param bool          $once 只获取一个有效返回值
	 * @return mixed
	 */
	public static function trigger($event, $params = null, bool $once = false){
		try{
			return Event::trigger($event, $params, $once);
		}catch(\Exception $e){
			Log::error($e->getMessage()."\n".$e->getTraceAsString());
		}
		return null;
	}

}
